package org.travel.travel2gether.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class HomeController {
	
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String index(HttpServletRequest request) {
		//redirect user to the page requested before authentication.
		//When authenticated page is accessible
		HttpSession session = request.getSession();
		Object ob = session.getAttribute("redirect");
		if(ob != null) {
			//redirect is removed because it must be used only once
			session.removeAttribute("redirect");
			return "redirect:/" + ob.toString();
		}
		return "home";
	}
}
